package com.weiaibenpao.demo.chislim.presenter;

import com.orhanobut.logger.Logger;
import com.weiaibenpao.demo.chislim.base.BasePresenter;
import com.weiaibenpao.demo.chislim.bean.IsLikeBean;
import com.weiaibenpao.demo.chislim.bean.MyZoneBean;
import com.weiaibenpao.demo.chislim.bean.UserBean;
import com.weiaibenpao.demo.chislim.retrofit.RetrofitUtils;
import com.weiaibenpao.demo.chislim.retrofit.rx.NetWorkTransformer;
import com.weiaibenpao.demo.chislim.retrofit.rx.SimpleObserver;
import com.weiaibenpao.demo.chislim.view.ZoneView;

/**
 * Created by wlx on 2018/1/11.
 */

public class ZonePresenter extends BasePresenter<ZoneView> {
    /**
     *
     * @param userId 个人详情的用户id
     * @param nowUserId 当前登录的用户id
     * @param page
     */
    public void getLatestMoments(int userId,int nowUserId,int page){
        RetrofitUtils
                .getAPIService()
                .getUserHumorPage(userId,page,  Integer.MAX_VALUE,nowUserId)
                .compose(new NetWorkTransformer<MyZoneBean>())
//                .compose(new LoadingTransformer<MyZoneBean>(mContext))
                .subscribe(new SimpleObserver<MyZoneBean>(mCompositeDisposable) {
                    @Override
                    public void call(MyZoneBean bean) {
                        getView().onGetMomentListSuccess(bean);
                    }

                    @Override
                    public void showErrorMsg(String message) {
                        super.showErrorMsg(message);
                        getView().onFail();
                    }
                });
    }

    /**
     *
     * @param userId 当前登录的用户id
     * @param beUserId 被关注的用户id
     */
    public void careOrUnCare(int userId, int beUserId){
        RetrofitUtils
                .getAPIService()
                .updateAttention(userId,beUserId)
                .compose(new NetWorkTransformer())
                .subscribe(new SimpleObserver<Object>(mCompositeDisposable) {
                    @Override
                    public void call(Object o) {
                        getView().onCareOrUnCareSuccess();
                    }
                });
    }
    public void likeOrUnLike(int userId, int momentId, final int position){
        Logger.e("likeOrUnLike----->");
        RetrofitUtils
                .getAPIService()
                .likeOrUnLike(userId,momentId)
                .compose(new NetWorkTransformer<IsLikeBean>())
                .subscribe(new SimpleObserver<IsLikeBean>(mCompositeDisposable) {
                    @Override
                    public void call(IsLikeBean bean) {
                        getView().onLikeOrUnlikeSuccess(bean.getIsLike(),position);
                    }

                });
    }
    public void report(int userId,int targetId,int type,String content){
        RetrofitUtils
                .getAPIService()
                .report(userId,targetId,type,content)
                .compose(new NetWorkTransformer())
                .subscribe(new SimpleObserver(mCompositeDisposable) {
                    @Override
                    public void call(Object bean) {
                        getView().onReportSuccess();
                    }

                });
    }


    public void deleteMoment(int userId, int momentId, final int position){
        RetrofitUtils
                .getAPIService()
                .deleteMoment(userId,momentId)
                .compose(new NetWorkTransformer())
                .subscribe(new SimpleObserver(mCompositeDisposable) {
                    @Override
                    public void call(Object bean) {
                        getView().onDeleteSuccess(position);
                    }

                });
    }

    /**
     * @Query("userId") int userId,
     @Query("userImage") String userImage,
     @Query("userName") String userName,
     @Query("userSex") String userSex,
     @Query("userHeigh") int userHeight,
     @Query("userWeight") float userWeight,
     @Query("userBirth") String userBirth,
     @Query("userIntru") String userSign,
     @Query("bgImage") String bgImage
     * @param userId
     * @param bgImage
     */
    public void upDataInfo(int userId,String bgImage) {
        RetrofitUtils.getAPIService().updDataInfo(userId, null, "", "", 0, 0, "", "",bgImage).
                compose(new NetWorkTransformer<UserBean>()).
//                compose(new LoadingTransformer<UserBean>(mContext)).
                subscribe(new SimpleObserver<UserBean>(mCompositeDisposable) {
                    @Override
                    public void call(UserBean userBean) {
                        getView().upDataInfoSuccess(userBean);
                    }


                });
    }
//    /**
//     * POST/fans/getAttentionList
//     关注列表分页接口
//     */
//    public void getAttentionList(int userId,int page) {
//        RetrofitUtils.getAPIService().getAttentionList(userId, page, Constant.DEFAULT_PAGE_SIZE).
//                compose(new NetWorkTransformer<FansAttentionListBean>()).
//                compose(new LoadingTransformer<FansAttentionListBean>(mContext)).
//                subscribe(new SimpleObserver<FansAttentionListBean>(mCompositeDisposable) {
//                    @Override
//                    public void call(FansAttentionListBean userBean) {
//                        getView().upAttentionListSuccess(userBean);
//                    }
//
//
//                });
//    }
//    /**
//     * POST/fans/getFansList
//     粉丝列表分页接口
//     */
//    public void getFansList(int userId,int page) {
//        RetrofitUtils.getAPIService().getAttentionList(userId,page, Constant.DEFAULT_PAGE_SIZE).
//                compose(new NetWorkTransformer<FansAttentionListBean>()).
//                compose(new LoadingTransformer<FansAttentionListBean>(mContext)).
//                subscribe(new SimpleObserver<FansAttentionListBean>(mCompositeDisposable) {
//                    @Override
//                    public void call(FansAttentionListBean userBean) {
//                        getView().upAttentionListSuccess(userBean);
//                    }
//
//
//                });
//    }
}
